package tmi.li.txclck;


import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class TxClckReceiver extends BroadcastReceiver{
	static String TAG = "tmi.li.txclck.TxClckReceiver";
	
	@Override
    public void onReceive(Context context, Intent intent) {
		//since we dont check what broadcast we received we skip that part
        //String action = intent.getAction();
        
		//getting the app widget Manager instance
		AppWidgetManager gm = AppWidgetManager.getInstance(context);
		
		// a string containing the ids seperated by a semicolon
		TxPref txpref = new TxPref(TxPref.PREFS_NAME_TXCLCK);
        String ids = txpref.getIds(context);
        
        //if ids arent null or ids containing a semikolon u have more then one widget to update
        if(ids != null && ids.contains(";")) {
        	
        	//splitting the string using the char ; so we have a array with all the ids 
        	String[] appWidgetIds = ids.split(";");
        	for(int i = 0; i < appWidgetIds.length; i++) {
        		//updating each widget
        		TxClckProvider.updateWidget(context, gm, Integer.valueOf(appWidgetIds[i]));
        	}
        	
        //when ids dont containt a semicolon but arent null u have only one widget to update
        }else if(ids != null){
        	
        	//updating the widget
        	TxClckProvider.updateWidget(context, gm, Integer.valueOf(ids));
       
        }else {
        	// this shouldnt happen at all ;)
        }
       
    }
}